﻿<template>
    <div class="container daily" style="width:99%;margin-top:-25px;">
        <!-- 查询条件 -->
        <div class="query-box">
            <el-form :model="queryBox" status-icon ref="queryBox">
                <div class="schoolBoxCont">
                    <div class="schoolBoxContItem" style="width:30%">
                        <el-form-item label prop="name">
                            <div class="schoolBoxContItemTitle">创建时间</div>
                            <div class="schoolBoxContItemInput" style="width:100%">
                                <el-date-picker
                                v-model="trackingDate"
                                type="daterange"
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                :default-time="['00:00:00', '23:59:59']"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                format="yyyy-MM-dd HH:mm:ss"
                            ></el-date-picker>
                            </div>
                        </el-form-item>
                    </div>

                </div>
            </el-form>
            <div class="from-btns">
                <kt-button
                    :label="$t('action.reset')"
                    perms="true"
                    type="primary"
                    @click="reset('queryBox')"
                />
                <kt-button
                    :label="$t('action.search')"
                    perms="true"
                    type="primary"
                    @click="get_subcentersearch"
                />
            </div>
        </div>
        <div class="fr" style="margin-bottom:20px">
            <kt-button
                label="生成当天日报"
                type="primary"
                :perms="btnAdd"
                @click="handleNewADD"
            ></kt-button>
            <!-- perms="directCampCenter:Daily:add" -->
        </div>
        <!--表格内容栏-->
        <div class="btn">
            <Crm-table
                @selectionChange="selectionChange"
                class="table-width"
                :showBatchDelete='false'
                Daily
                :permsSee="tableBtnSee"
                :data="pageResult"
                :columns="columns"
                :loading="loading"
                @findPage="findPage"
                @handleEdit="handleEdit"
                @handleSee="handleSee"
                @handleDeleteDic="handleDelete"
            ></Crm-table>
            <!-- permsSee="directCampCenter:Daily:see" -->
        </div>
        <!-- 查看详情 -->
        <el-dialog
            title="日报详情"
            :visible.sync="dialogVisible"
            width="50%"
        >
            <el-table :data="tableData">
                <el-table-column prop="createDate" label="日期" width="200"></el-table-column>
                <el-table-column label="详情">
                    <template slot-scope="scope">
                        <el-input
                            style="color:#000"
                            :disabled="scope.row.createType==2"
                            v-model="scope.row.optionDetail"
                            autosize
                            type="textarea"
                            @click.native="inputClick(scope.row)"
                        ></el-input>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="100">
                    <template slot-scope="scope">
                        <el-button
                            type="primary"
                            plain
                            perms="true"
                            :size="size"
                            :disabled="scope.row.createType==2"
                            @click="handleEdit(scope.row)"
                        >提交</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageRequest2.pageNum"
                :page-sizes="[10, 100, 200, 500]"
                :page-size="10"
                layout="total, sizes, prev, pager, next, jumper"
                :total="addDailyTotal"
                style="float:right;margin:20px 0"
            ></el-pagination>
            <el-button @click="addDailyTody" type="primary" style="margin-top:20px">添加日报</el-button>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import KtButton from "@/views/Core/KtButton";
import StTable from "@/views/Core/StTable";
import CrmTable from "@/views/Core/CrmTable";
import CrmSwitch from "@/views/Core/CrmSwitch";
import { CodeToText } from "element-china-area-data";
import { baseUrl } from "@/utils/global";
import { regionDataPlus } from "element-china-area-data";
import axios from "axios";
import Checkrepeat from "@/views/Core/Checkrepeat";
import Cookies from "js-cookie";
export default {
    name: "Daily",
    components: {
        PopupTreeInput,
        CrmTable,
        KtButton,
        CrmSwitch,
        Checkrepeat
    },
    data() {
        return {
            isShowFlag: 0, //0:初始化部门、人员不显示  1:部门显示 2：人员显示
            showBatchDelete: false,
            mytime: "",
            size: "mini",
            selectDisabled: false, //跟进弹窗客户进展状态
            typeDisabled: false,
            trackingDate: [], //跟进时间数组
            columns: [
                { type: "index", label: "序号", minWidth: 50 },
                { prop: "userName", label: "创建人", minWidth: 180 },
                { prop: "createDate", label: "创建时间", minWidth: 100 }
            ],
            columns2: [
                { type: "index", label: "序号", minWidth: 50 },
                { prop: "createDate", label: "日期", minWidth: 120 },
                { prop: "optionDetail", label: "详情", minWidth: 100 }
            ],
            pageResult: {
                content: []
            },
            selectionsLength: "",
            selections: [], //选中列表集合
            loading: false, // 加载标识
            dialogVisible: false,
            addDailyFormDetail: {},
            tableData: [],
            pageRequest: { pageNum: 1, pageSize: 10 },
            pageRequest2: { pageNum: 1, pageSize: 10 },
            textareaDaily: false,
            addDailyTotal: "",
            queryBox:{},
            dataType: this.$route.fullPath.indexOf('dataType=2')>-1?2:'', // 根据参数动态添加权限按钮
            tableBtnSee:'',
            btnAdd:''
        };
    },
    methods: {
        transformRouteBtnParam(){
            if(this.dataType&&this.dataType==2){
                this.tableBtnSee='directCampCenter:tz:Daily:see'
                this.btnAdd='directCampCenter:tz:Daily:add'
            }else{
                this.tableBtnSee='directCampCenter:Daily:see'
                this.btnAdd='directCampCenter:Daily:add'
            }
        },
        inputClick(row){
            if(row.relationType){
                if(row.relationType==1){
                    this.$router.push({
                        path: "/Customerfile/School",
                        query: {
                            id: row.relationId
                        }
                    });
                }
                if(row.relationType==2){
                    this.$router.push({
                        path: "/Customerfile/ThreeFileBase",
                        query: {
                            id: row.relationId
                        }
                    });
                }
                this.dialogVisible=false
                
            }
        },
        // 获取分页数据
        findPage: function(data) {
            if (data !== null) {
                this.loading = true;
                this.pageRequest = data.pageRequest;
            }
            let dataType=''
            // 获取参数判断是否是商务拓展中心
            if(this.$route.fullPath.indexOf('dataType=2')>-1){
                dataType = 2;
            }
            if(dataType==2){
                this.queryBox.dataType=2
            }
            this.queryBox.pageNum = this.pageRequest.pageNum;
            this.queryBox.pageSize = this.pageRequest.pageSize;
            this.$api.agent
                .dailyList(this.queryBox)
                .then(res => {
                    let content = { content: res.data, totalSize: res.total };
                    this.pageResult = content;
                    this.pageResult.content.forEach(item => {
                        // 去掉时间的时分秒
                        item.createDate = /\d{4}-\d{1,2}-\d{1,2}/g.exec(
                            item.createDate
                        );
                    });

                    this.loading = false;
                })
                .then(data != null ? data.callback : "");
        },
        handleSizeChange(pageSize) {
            this.pageRequest2.pageSize = pageSize;
            this.getList(this.pageRequest2);
        },
        handleCurrentChange(pageNum) {
            this.pageRequest2.pageNum = pageNum;
            this.getList(this.pageRequest2);
        },
        // 获取日报详情数据列表
        getList(params) {
            if (params !== null) {
                this.pageRequest2 = params;
            }
            this.$api.agent
                .dailyDetailList({
                    dailyId: this.addDailyFormDetail.id,
                    pageNum: this.pageRequest2.pageNum,
                    pageSize: this.pageRequest2.pageSize
                })
                .then(res => {
                    if (res.result == 2) {
                        this.$message({ message: res.msg, type: "error" });
                    } else {
                        this.tableData = res.data;
                        this.addDailyTotal = res.total;
                    }
                });
        },
        // 搜索
        get_subcentersearch() {
            this.loading = true;
            this.pageRequest.pageNum = 1;
            if(this.trackingDate.length>0){
                this.queryBox.createDateStart=this.trackingDate[0]
                this.queryBox.createDateEnd=this.trackingDate[1]
            }
            this.findPage(null);
        },

        // 重置
        reset(queryBox) {
            this.trackingDate=[];
            this.queryBox.createDateStart=''
            this.queryBox.createDateEnd=''
            this.findPage(null);
        },

        // 批量删除
        handleBatchDelete() {
            let schids = this.selections.map(item => item.id);
            this.$confirm(
                "确认删除这" + this.selections.length + "个吗？",
                "提示",
                {}
            ).then(() => {
                this.editLoading = true;
                this.$api.agent
                    .schoolTripartiteDeleteBatchIds({
                        ids: this.ids
                        // dateType: 4
                    })
                    .then(res => {
                        if (res.result == 1) {
                            this.$message({
                                message: res.msg,
                                type: "success"
                            });
                            this.findPage(null);
                        } else {
                            this.$message({ message: res.msg, type: "error" });
                        }
                    });
            });
        },
        // 删除
        handleDelete(params) {
            this.$confirm("确定删除？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                this.$api.agent
                    .deleteTripartite({
                        id: params.row.id
                    })
                    .then(res => {
                        if (res.result == 2) {
                            this.$message({ message: res.msg, type: "error" });
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "success"
                            });
                            this.findPage(null);
                        }
                    });
            });
        },

        // 查看客户档案
        handleSee: function(params) {
            this.dialogVisible = true;
            this.addDailyFormDetail.id = params.row.id;
            this.addDailyFormDetail.dailyId = params.row.id;
            this.$api.agent
                .dailyDetailList({
                    dailyId: params.row.id
                })
                .then(res => {
                    if (res.result == 2) {
                        this.$message({ message: res.msg, type: "error" });
                    } else {
                        this.tableData = res.data;
                        this.addDailyTotal = res.total;
                    }
                });
        },
        // 修改客户档案
        handleEdit: function(params) {
            this.addDailyFormDetail.optionDetail = params.optionDetail;
            if (!params.id) {
                this.$api.agent
                    .addDailyDetail(this.addDailyFormDetail)
                    .then(res => {
                        if (res.result == 2) {
                            this.$message({ message: res.msg, type: "error" });
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "success"
                            });
                            this.$api.agent
                                .dailyDetailList({
                                    dailyId: this.addDailyFormDetail.id
                                })
                                .then(res => {
                                    if (res.result == 2) {
                                        this.$message({
                                            message: res.msg,
                                            type: "error"
                                        });
                                    } else {
                                        this.tableData = res.data;
                                        this.addDailyTotal = res.total;
                                    }
                                });
                        }
                    });
            } else {
                this.$api.agent.updateDailyDetail(params).then(res => {
                    if (res.result == 2) {
                        this.$message({ message: res.msg, type: "error" });
                    } else {
                        this.$message({ message: res.msg, type: "success" });
                        this.$api.agent
                                .dailyDetailList({
                                    dailyId: this.addDailyFormDetail.id
                                })
                                .then(res => {
                                    if (res.result == 2) {
                                        this.$message({
                                            message: res.msg,
                                            type: "error"
                                        });
                                    } else {
                                        this.tableData = res.data;
                                        this.addDailyTotal = res.total;
                                    }
                                });
                    }
                });
            }
        },
        addDailyTody() {
            this.textareaDaily = true;
            this.tableData.push({});
            console.log(this.tableData);
        },
        // 获取选中的表格数据
        selectionChange: function(params) {
            let selectionsLength = params.selections.length;
            this.selections = params.selections;
            this.ids = [];
            let idstu = this.selections.map(item => item.id);
            this.ids = idstu;
        },
        handleNewADD(){
            this.$api.agent
            .schoolAddDaily()
            .then(res => {
                if (res.result == 2) {
                    this.$message({ message: res.msg, type: 'error' });
                } else {
                    this.$message({ message: res.msg, type: 'success' });
                    this.findPage(null)
                }
            });
        }
    },
    mounted() {
        this.transformRouteBtnParam()
    }
};
</script>
<style>
@import url("../../assets/queryBox.css");
</style>
<style lang="scss" scope>
.daily {
    .el-textarea.is-disabled .el-textarea__inner {
        color: #000;
    }
}
.add-btns .el-button:nth-child(1) {
    margin-right: 10px;
}
.second-contain-box {
    width: 95%;
    margin: 0 auto;
    .el-col {
        text-align: left;
        margin: 4px 0;
    }
    .el-row {
        margin: 0 0 !important;
    }
    .el-col i {
        font-style: normal;
        display: inline-block;
    }
}
.second-contain-box2 {
    .el-col i {
        margin-top: 0px !important;
    }
}
.schoolBoxCont {
    margin: 5px 5px;

    .schoolBoxContItem {
        margin-right: 10px;
        float: left;
        .el-form-item__content {
            display: flex;
            flex-direction: row;
        }
        .schoolBoxContItemTitle {
            background: #f5f7fa;
            width: 115px;
            border: 1px solid #dcdfe6;
            border-top-left-radius: 4px;
            border-bottom-left-radius: 4px;
            line-height: 39px;
            border-right: none;
        }
        .schoolBoxContItemInput {
            width: 150px;
            line-height: 39px;
            .el-date-editor.el-input,
            .el-date-editor.el-input__inner {
                width: 100%;
            }
        }
    }
}
</style>
